home *** CD-ROM | disk | FTP | other *** search
- /* a very simple news protocol POST client
- Usage: nntp <group_name> <subject> <file_to_send>
- */
-
- /* SET THESE */
-
- host = "" /* news host name */
- port = 119 /* port */
- RealName = "" /* your name */
- email = "" /* your email addr */
- gmtoff = "+0100" /* gmt offset */
-
- /****/
-
- l="rmh.library";if ~show("L",l) then;if ~addlib(l,0,-30) then exit
- if AddLibrary("rexxsupport.library","rxsocket.library")~=0 then exit
-
- prg=ProgramName("NOEXT")
- if ~RMH_ReadArgs("GROUP/A,SUBJECT/A,FILE/A") then do
- call PrintFault()
- exit
- end
-
- if ~open(in,parm.2.value) then do
- call PrintFault()
- exit
- end
-
- say "opening connection..."
- sock = OpenConnection("tcp",port,host)
- if sock<0 then do
- select
- when sock=-2 then say prg": can't find <"host">"
- otherwise say prg": can't connect <"host":"port">" errorstring()
- end
- exit
- end
-
- say "entering..."
- call rec
-
- say "sending message..."
- call sen "POST"
- call rec
-
- if GetSockName(sock,"LOCALE")<0 then do
- say prg": can't find socket locale infos"
- exit
- end
- thisHost=locale.addraddr
-
- msg=,
- "From:" realname "<"email">" || "D0A"x ||,
- "Newsgroups:" parm.0.value || "D0A"x ||,
- "Date:" date() time() gmtoff || "D0A"x ||,
- "Message-ID: <smtp"time(s)"@"thisHost">" || "D0A"x ||,
- "X-Newsposter: nntp.rexx - Amiga ARexx nntp sender" || "D0A"x ||,
- "Subject:" parm.1.value || "D0A"x
- call sen msg
-
- do while ~eof(in)
- blk=readch(in,512)
- if blk~="" then call sen blk
- end
-
- call sen "D0A"x || "."
- call rec
-
- call sen "QUIT"
- call rec
-
- say "done."
- exit
-
- sen:
- parse arg string
- string=string || "D0A"x
- if send(sock,string)~=length(string) then do
- say prg": send error" ErrorString()
- exit
- end
- return
-
- rec:
- if recv(sock,"BUF",256)<0 then do
- say prg": recv error" ErrorString()
- exit
- end
- parse var BUF code rest "D0A"x
- if code>=400 then do
- say "error from server: ("code")"rest
- exit
- end
- return
-